package jp.sourceforge.akjrcp.flvtools.basic;

import jp.sourceforge.akjrcp.akj_betas.Akj_betasPlugin;
import jp.sourceforge.akjrcp.akj_betas.Messages;
import jp.sourceforge.akjrcp.ffmpeg.FFMpegOptions;

import org.eclipse.jface.preference.BooleanFieldEditor;
import org.eclipse.jface.preference.FieldEditorPreferencePage;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.preference.IntegerFieldEditor;
import org.eclipse.jface.preference.RadioGroupFieldEditor;
import org.eclipse.jface.preference.StringFieldEditor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;

public class ShareSettingPage extends FieldEditorPreferencePage
implements IWorkbenchPreferencePage {
	
	public static final int RATE_8000=8000;
	public static final int RATE_11025=11025;
	public static final int RATE_12000=12000;
	public static final int RATE_16000=16000;
	public static final int RATE_22050=22050;
	public static final int RATE_24000=24000;
	public static final int RATE_32000=32000;
	public static final int RATE_44100=44100;
	public static final int RATE_48000=48000;
	
    //public static final String EXPORT_WAVE_SAMPLEBIT = "export.wave.samplebit"; //$NON-NLS-1$
	public static final String EXPORT_WAVE_SAMPLERATE = "export.wave.samplerate"; //$NON-NLS-1$
	public static final String EXPORT_WAVE_CHANNEL = "export.wave.channel"; //$NON-NLS-1$
    public static final String FFMPEG_OPTION="ffmpeg_option"; //$NON-NLS-1$
    public static final String AUDIO_BITRATE="audio_bitrate"; //$NON-NLS-1$
    public static final String VIDEO_BITRATE="video_bitrate"; //$NON-NLS-1$
    public static final String VIDEO_FPS="video_fps"; //$NON-NLS-1$
//	public static final String VIDEO_CODEC = "video_codec";

	public static final String IMAGE_TIME = "image_time";
	
	public static final String IS_DELETE_AVI="explorer.delte_after_conver_avi";
	public static final String IS_DELETE_WMV="explorer.delte_after_conver_wmv";
	public static final String IS_DELETE_MPG="explorer.delte_after_conver_mpg";
	public static final String IS_DELETE_MP4="explorer.delte_after_conver_mp4";
	
	public static final String VIDEO_SIZE="explorer.video_size"; //$NON-NLS-1$
	public static final String VIDEO_FPS_OTHER="explorer.video_fps.other"; //$NON-NLS-1$
	public static final String VIDEO_SIZE_OTHER="explorer.video_size.other"; //$NON-NLS-1$
	public ShareSettingPage() {
		super(GRID);
		setPreferenceStore(Akj_betasPlugin.getDefault().getPreferenceStore());
		setDescription(Messages.getString("explorer.share_description")); //$NON-NLS-1$
		
		initializeDefaults();
	}
	
	private void initializeDefaults() {
		
		// no one call it before open them

	}

	public static String getVideoFps(IPreferenceStore store){
		String ret=null;
		ret=store.getString(VIDEO_FPS);
		if(ret.equals(VIDEO_FPS_OTHER)){
			ret=store.getString(VIDEO_FPS_OTHER);
		}
		if(ret.equals("")){
			return null;
		}
		return ret;
	}
	
	public static String getVideoSize(IPreferenceStore store){
		String ret=null;
		ret=store.getString(VIDEO_SIZE);
		if(ret.equals(VIDEO_SIZE_OTHER)){
			ret=store.getString(VIDEO_SIZE_OTHER);
		}
		if(ret.equals("")){
			return null;
		}
		return ret;
	}
	protected void createFieldEditors() {
		

    	addField(new IntegerFieldEditor(VIDEO_BITRATE,Messages.getString("video_bitrate"),getFieldEditorParent())); //$NON-NLS-1$
    	
    	//addField(new StringFieldEditor(VIDEO_FPS,Messages.getString("video_fps"),getFieldEditorParent())); //$NON-NLS-1$
        
		addField(new RadioGroupFieldEditor(
				VIDEO_SIZE,
				Messages.getString("explorer.video_size"), // //$NON-NLS-1$
				3,
				new String[][] { 
					
				{ Messages.getString("explorer.size_640_480"), FFMpegOptions.SIZE_640x480 }, //$NON-NLS-1$ //$NON-NLS-2$
				{ Messages.getString("explorer.size_512_384"), FFMpegOptions.SIZE_512x384 }, //$NON-NLS-1$ //$NON-NLS-2$
				{ Messages.getString("explorer.size_320_240"), FFMpegOptions.SIZE_320x240 }, //$NON-NLS-1$ //$NON-NLS-2$
				{ Messages.getString("explorer.size_same"), "" },
				{ Messages.getString("explorer.size_other"), VIDEO_SIZE_OTHER }, //$NON-NLS-1$ //$NON-NLS-2$
			}, getFieldEditorParent()));
		addField(new StringFieldEditor(VIDEO_SIZE_OTHER,Messages.getString("explorer.size_other_value"),getFieldEditorParent())); //$NON-NLS-1$
		
		addField(new RadioGroupFieldEditor(
				VIDEO_FPS,
				Messages.getString("video_fps"), // //$NON-NLS-1$
				3,
				new String[][] { 
				
				{ Messages.getString("explorer.fps_30"), ""+FFMpegOptions.VIDEO_RATE_30 }, //$NON-NLS-1$ //$NON-NLS-2$
				{ Messages.getString("explorer.fps_2997"), ""+FFMpegOptions.VIDEO_RATE_29_97 }, //$NON-NLS-1$ //$NON-NLS-2$
				{ Messages.getString("explorer.fps_15"), ""+FFMpegOptions.VIDEO_RATE_15 }, //$NON-NLS-1$ //$NON-NLS-2$
				{ Messages.getString("explorer.fps_same"), "" },
				{ Messages.getString("explorer.fps_other"), VIDEO_FPS_OTHER }, //$NON-NLS-1$ //$NON-NLS-2$
			}, getFieldEditorParent()));
    	addField(new StringFieldEditor(VIDEO_FPS_OTHER,Messages.getString("explorer.fps_value"),getFieldEditorParent())); //$NON-NLS-1$
    	
    	
        
    
        
        
        addField(new RadioGroupFieldEditor(
		        EXPORT_WAVE_SAMPLERATE,
				Messages.getString("sample_rate"), // //$NON-NLS-1$
				4,
				new String[][] { { ShareSettingPage.RATE_8000+" khz", ShareSettingPage.RATE_8000+"" }, { //$NON-NLS-1$ //$NON-NLS-2$
					ShareSettingPage.RATE_11025+" khz", ShareSettingPage.RATE_11025+""   //$NON-NLS-1$ //$NON-NLS-2$
				    
				},
				{ ShareSettingPage.RATE_12000+" hz", ShareSettingPage.RATE_12000+"" }, //$NON-NLS-1$ //$NON-NLS-2$
				{ ShareSettingPage.RATE_16000+" hz", ShareSettingPage.RATE_16000+"" }, //$NON-NLS-1$ //$NON-NLS-2$
				{ ShareSettingPage.RATE_22050+" hz", ShareSettingPage.RATE_22050+"" }, //$NON-NLS-1$ //$NON-NLS-2$
				{ ShareSettingPage.RATE_24000+" hz", ShareSettingPage.RATE_24000+"" }, //$NON-NLS-1$ //$NON-NLS-2$
				{ ShareSettingPage.RATE_32000+" hz", ShareSettingPage.RATE_32000+"" }, //$NON-NLS-1$ //$NON-NLS-2$
				{ ShareSettingPage.RATE_44100+" hz", ShareSettingPage.RATE_44100+"" }, //$NON-NLS-1$ //$NON-NLS-2$
				{ ShareSettingPage.RATE_48000+" hz", ShareSettingPage.RATE_48000+"" }, //$NON-NLS-1$ //$NON-NLS-2$
				
			}, getFieldEditorParent()));
        
		addField(new RadioGroupFieldEditor(
		        EXPORT_WAVE_CHANNEL,
			Messages.getString("channel"), //$NON-NLS-1$
			2,
			new String[][] { { Messages.getString("stereo"), "2" }, {Messages.getString("monoral") ,"1"}}, getFieldEditorParent())); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
       
		addField(new IntegerFieldEditor(AUDIO_BITRATE,Messages.getString("audio_bitrate"),getFieldEditorParent())); //$NON-NLS-1$
        
        addField(new StringFieldEditor(FFMPEG_OPTION,Messages.getString("ffmpeg_option"),getFieldEditorParent())); //$NON-NLS-1$
        
       // addField(new StringFieldEditor(VIDEO_CODEC,Messages.getString("video_codec_text"),getFieldEditorParent())); //$NON-NLS-1$
        
        
        addField(new StringFieldEditor(IMAGE_TIME,Messages.getString("image_time_text"),getFieldEditorParent())); //$NON-NLS-1$
        
        new Label(getFieldEditorParent(),SWT.NULL).setText(Messages.getString("explorer.delte_after_conver"));
        Composite deleteFiles=new Composite(getFieldEditorParent(),SWT.NULL);
        deleteFiles.setLayout(new GridLayout(4,false));
        addField(new BooleanFieldEditor(IS_DELETE_AVI,Messages.getString("explorer.delte_after_conver_avi"),new Composite(deleteFiles,SWT.NULL)));
        addField(new BooleanFieldEditor(IS_DELETE_MPG,Messages.getString("explorer.delte_after_conver_mpg"),new Composite(deleteFiles,SWT.NULL)));
        addField(new BooleanFieldEditor(IS_DELETE_WMV,Messages.getString("explorer.delte_after_conver_wmv"),new Composite(deleteFiles,SWT.NULL)));
        addField(new BooleanFieldEditor(IS_DELETE_MP4,Messages.getString("explorer.delte_after_conver_mp4"),new Composite(deleteFiles,SWT.NULL)));
        
	}

	public void init(IWorkbench workbench) {
		// TODO Auto-generated method stub
		
	}

}
